<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>中盈优创交付考试系统</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css">
    <style>
        body {
            margin: 0;
            padding: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            background: linear-gradient(-45deg, #ee7752, #e73c7e, #23a6d5, #23d5ab);
            background-size: 400% 400%;
            animation: gradient 15s ease infinite;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }

        @keyframes gradient {
            0% {
                background-position: 0% 50%;
            }

            50% {
                background-position: 100% 50%;
            }

            100% {
                background-position: 0% 50%;
            }
        }

        .login-container {
            background-color: white;
            border-radius: 10px;
            box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
            padding: 40px;
            width: 800px;
            display: flex;
            flex-direction: row;
            justify-content: space-between;
            align-items: center;
        }

        .login-form {
            flex: 1;
            margin-right: 20px;
        }

        .login-container h2 {
            text-align: center;
            margin-bottom: 30px;
            color: #333;
        }

        .input-group {
            position: relative;
            margin-bottom: 25px;
        }

        .input-group input {
            width: 100%;
            padding: 12px 15px;
            border: 1px solid #ccc;
            border-radius: 5px;
            font-size: 16px;
        }

        .input-group i {
            position: absolute;
            top: 50%;
            right: 15px;
            transform: translateY(-50%);
            color: #999;
        }

        .btn-login {
            width: 100%;
            padding: 12px;
            background-color: #007BFF;
            color: white;
            border: none;
            border-radius: 5px;
            font-size: 16px;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }

        .btn-login:hover {
            background-color: #0056b3;
        }

        .forgot-password {
            text-align: right;
            margin-top: 10px;
        }

        .forgot-password a {
            color: #007BFF;
            text-decoration: none;
        }

        .forgot-password a:hover {
            text-decoration: underline;
        }

        .custom-logo-section {
            flex: 1;
            text-align: center;
            border-left: 1px solid #ccc;
            padding-left: 20px;
        }

        .custom-logo-section p {
            margin-bottom: 15px;
            color: #666;
            font-size: 20px;
            font-weight: bold;
        }

        .custom-logo {
            max-width: 200px;
            height: auto;
            margin-top: 20px;
        }
    </style>
</head>
<body>
<div class="login-container">
    <div class="login-form">
        <h2>登录</h2>
        <form id="loginForm" onsubmit="return login(event)">
            <div class="input-group">
                <input type="text" id="username" name="username" placeholder="用户名" required>
                <i class="fa-solid fa-user"></i>
            </div>
            <div class="input-group">
                <input type="password" id="password" name="password" placeholder="密码" required>
                <i class="fa-solid fa-lock"></i>
            </div>
            <button type="submit" id="btn" class="btn-login">登录</button>
            <div class="forgot-password">
                <a href="#">忘记密码?</a>
            </div>
        </form>
        <div class="alert alert-danger mt-3" id="error-message" style="display: none;">
            用户名或密码错误。
        </div>
    </div>
    <div class="custom-logo-section">
        <p>中盈优创交付考试系统</p>
        <img src="logo.png" alt="中盈优创交付考试系统" class="custom-logo">
    </div>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
<script>
    function login(event) {
        event.preventDefault();
        const username = document.getElementById("username").value;
        const password = document.getElementById("password").value;
        if (!username || !password) {
            alert("请输入用户名和密码");
            return false;
        }

        fetch('/login', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json;charset=UTF-8'
            },
            body: JSON.stringify({username: username, password: password})
        })
            .then(response => {
                if (response.ok) {
                    return response.json();
                }
                throw new Error('网络错误');
            })
            .then(data => {
                if (data.id) {
                    alert('登录成功');
                    location.href = '/index.html';
                } else {
                    alert('账号或密码错误');
                }
            })
            .catch(error => {
                console.error('Error:', error);
                alert('登录失败，请检查网络连接');
            });
        return false;
    }
</script>
</body>
</html>
